#include<bits/stdc++.h>
using namespace std;
const int N=3e3+5;
bool st;
int n,m,u[N][N],d[N][N],l[N][N],r[N][N],sum[N][N],sum1[N][N],ans1[N][N];
long long ans;
char a[N][N];
bool ed;
void fz(int le,int ri,int x,int y)
{
	if(le>=ri||x>=y) return;
	if(ri-le+1>=y-x+1)
	{
		int mid=(le+ri)/2;
		fz(le,mid-1,x,y),fz(mid+1,ri,x,y);
		for(int i=x-1;i<=y+1;++i)
			for(int j=x-1;j<=y+1;++j)
				sum[i][j]=sum1[i][j]=0;
		for(int i=x;i<=y;++i)
			for(int j=x;j<=y;++j)
				ans1[i][j]=0;
		for(int j=x;j<=y;++j)
			for(int i=mid+1;i<=min(d[mid][j],ri);++i)
				++sum[j][min(r[i][j],y)],++sum1[j][max(x,l[i][j])];
		for(int i=x;i<=y;++i)
		{
			for(int j=y;j>=x;--j)
				sum[i][j]=sum[i][j]+sum[i][j+1];
			for(int j=x;j<=y;++j)
				sum1[i][j]=sum1[i][j]+sum1[i][j-1];
		}
		for(int i=x;i<=y;++i)
		{
			int op=1;
			for(int j=i+1;j<=y;++j)
			{
				if(a[mid][i]!=a[mid][j]) 
				{
					op=0;
					continue;
				}
				if(d[mid][i]>d[mid][j])
					ans1[i][j]=sum1[j][i],ans+=sum1[j][i]*op;
				else
					ans1[i][j]=sum[i][j],ans+=sum[i][j]*op;
			}
		}
		for(int i=x-1;i<=y+1;++i)
			for(int j=x-1;j<=y+1;++j)
				sum[i][j]=sum1[i][j]=0;
		for(int j=x;j<=y;++j)
			for(int i=max(u[mid][j],le);i<mid;++i)
				++sum[j][min(r[i][j],y)],++sum1[j][max(x,l[i][j])];
		for(int i=x;i<=y;++i)
		{
			for(int j=y;j>=x;--j)
				sum[i][j]=sum[i][j]+sum[i][j+1];
			for(int j=x;j<=y;++j)
				sum1[i][j]=sum1[i][j]+sum1[i][j-1];
		}
		for(int i=x;i<=y;++i)
		{
			int op=1;
			for(int j=i+1;j<=y;++j)
			{
				if(a[mid][i]!=a[mid][j])
				{
					op=0;
					continue;
				} 
				if(u[mid][i]<u[mid][j])
					ans+=(ans1[i][j]+op)*sum1[j][i];
				else
					ans+=(ans1[i][j]+op)*sum[i][j];
			}
		}
	}
	else{
		int mid=(x+y)/2;
		fz(le,ri,x,mid-1),fz(le,ri,mid+1,y);
		for(int i=le-1;i<=ri+1;++i)
			for(int j=le-1;j<=ri+1;++j)
				sum[i][j]=sum1[i][j]=0;
		for(int i=le;i<=ri;++i)
			for(int j=le;j<=ri;++j)
				ans1[i][j]=0;
		for(int j=le;j<=ri;++j)
			for(int i=mid+1;i<=min(r[j][mid],y);++i)
				++sum[j][min(d[j][i],ri)],++sum1[j][max(le,u[j][i])];
		for(int i=le;i<=ri;++i)
		{
			for(int j=ri;j>=le;--j)
				sum[i][j]=sum[i][j]+sum[i][j+1];
			for(int j=le;j<=ri;++j)
				sum1[i][j]=sum1[i][j]+sum1[i][j-1];
		}
		for(int i=le;i<=ri;++i)
		{
			int op=1;
			for(int j=i+1;j<=ri;++j)
			{
				if(a[i][mid]!=a[j][mid])
				{
					op=0;
					continue;
				}
				if(r[i][mid]>r[j][mid])
					ans1[i][j]=sum1[j][i],ans+=sum1[j][i]*op;
				else
					ans1[i][j]=sum[i][j],ans+=sum[i][j]*op;
			}
		}
		for(int i=le-1;i<=ri+1;++i)
			for(int j=le-1;j<=ri+1;++j)
				sum[i][j]=sum1[i][j]=0;
		for(int j=le;j<=ri;++j)
			for(int i=max(l[j][mid],x);i<mid;++i)
				++sum[j][min(d[j][i],ri)],++sum1[j][max(le,u[j][i])];
		for(int i=le;i<=ri;++i)
		{
			for(int j=ri;j>=le;--j)
				sum[i][j]=sum[i][j]+sum[i][j+1];
			for(int j=le;j<=ri;++j)
				sum1[i][j]=sum1[i][j]+sum1[i][j-1];
		}
		for(int i=le;i<=ri;++i)
		{
			int op=1;
			for(int j=i+1;j<=ri;++j)
			{
				if(a[i][mid]!=a[j][mid])
				{
					op=0;
					continue;
				}
				if(l[i][mid]<l[j][mid])
					ans+=(ans1[i][j]+op)*sum1[j][i];
				else
					ans+=(ans1[i][j]+op)*sum[i][j];
			}
		}
	}
}
int main()
{
	freopen("star.in","r",stdin);
	freopen("star.out","w",stdout);
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin>>n>>m;
	for(int i=1;i<=n;++i)
		for(int j=1;j<=m;++j)
			cin>>a[i][j];
	for(int i=1;i<=n;++i)
		for(int j=1;j<=m;++j)
		{
			if(a[i][j]==a[i][j-1])
				l[i][j]=l[i][j-1];
			else
				l[i][j]=j;
			if(a[i][j]==a[i-1][j])
				u[i][j]=u[i-1][j];
			else
				u[i][j]=i;
		}
	for(int i=n;i>=1;--i)
		for(int j=m;j>=1;--j)
		{
			if(a[i][j]==a[i][j+1])
				r[i][j]=r[i][j+1];
			else
				r[i][j]=j;
			if(a[i][j]==a[i+1][j])
				d[i][j]=d[i+1][j];
			else
				d[i][j]=i;
		}
	fz(1,n,1,m);
	cout<<ans;
	return 0;
}
